<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/common/tags.jsp" %>
<!doctype html><!-- 此处doctype不能去掉，否则amaze样式会有奇怪问题 -->
<html class="no-js">
<head>
    <meta charset="utf-8">
    <title>编辑</title>
    <%@ include file="/common/amaze_meta.jsp" %>
</head>
<body>
<section data-am-widget="accordion" class="am-accordion am-accordion-gapped"
data-am-accordion='{  }'>
  <dl class="am-accordion-item am-active">
    <dt class="am-accordion-title"><span class="am-icon-search"></span> 查询</dt>
    <dd class="am-accordion-bd am-collapse am-in">
      <!-- 规避 Collapase 处理有 padding 的折叠内容计算计算有误问题， 加一个容器 -->
      <div class="am-accordion-content">
                
        <div class="search_tab" style="overflow:auto;">
        	<div class="tr">
        		<div class="label">名称</div><div class="value"><input type="text" name="name" class="am-form-field am-radius" value="${param.name}"></div>        		
        		<!-- <div class="label">类型</div>
        		<div class="value">
					<select name="type">
						<option value="abc">abc</option>
						<option value="b">b</option>
					</select>
        		</div> -->
        	</div> 
        	<div class="tr">        		
        		<div class="label">上传时间</div>
        		<div class="value" style="width:60%">
        			<input type="text" name="date_s" class="am-form-field am-date" placeholder="" data-am-datepicker readonly/>
        			--
        			<input type="text" name="date_e" class="am-form-field am-date" placeholder="" data-am-datepicker readonly/>
        		</div>
        	</div>       	  
        	<div class="btn"><button id="doSearch" type="button" class="am-btn am-btn-success">查询</button></div>     	
        </div>
      </div>
    </dd>
  </dl>
  </section>

<div class="am-g">
    <div class="am-u-md-6 am-cf">
        <div class="am-fl am-cf">
            <div class="am-btn-toolbar am-fl">
                <div class="am-btn-group am-btn-group-xs">
                    <button id="btn_view" type="button" type="button" class="am-btn am-btn-default"><span class="am-icon-search"></span> 查看详情</button>    
                    <button id="btn_batch" type="button" type="button" class="am-btn am-btn-default"><span class="am-icon-sign-out"></span> 批量审核通过</button>                
                </div>
            </div>
        </div>
    </div>
</div>

<div class="am-g">
<div class="am-u-sm-12">
<form class="am-form" action="a.html">
<table class="am-table am-table-striped am-table-hover table-main">
<thead>
<tr>
    <th class="table-check"><input id="select_all" type="checkbox" /></th>
    <th class="table-id">ID</th>
    <th class="table-title">名称</th>
    <th class="table-type">价格</th>
    <th class="table-author">商家</th>
    <th class="table-date">上传日期</th>
    <th class="table-set">操作</th>
</tr>
</thead>
<tbody id="pageList">

<c:forEach items="${pager.records}" var="item">
<tr>
    <td><input type="checkbox" /><input type="hidden" value="${item.id}"></td>
    <td>${item.id}</td>
    <td><a href="#">${item.name}</a></td>
    <td>${item.price}</td>
    <td>${item.sellername}</td>
    <td>${item.create_time}</td>
    <td>
        <div class="am-btn-toolbar">
            <div class="am-btn-group am-btn-group-xs">
                <button type="button" onclick="doAudit([${item.id}])" class="am-btn am-btn-default am-btn-xs am-text-secondary" data-am-modal="{target: '#modal-1', closeViaDimmer: 0}"><span class="am-icon-sign-out"></span> 审核通过</button>               
            </div>
        </div>
    </td>
</tr>
</c:forEach>

</tbody>
</table>
<div id="am-page"></div>
<!-- confirm panel -->
<div class="am-modal am-modal-confirm" tabindex="-1" id="my-confirm">
  <div class="am-modal-dialog">
    <div class="am-modal-hd"></div>
    <div class="am-modal-bd">
      确定要审批这些记录吗？
    </div>
    <div class="am-modal-footer">
      <span class="am-modal-btn" data-am-modal-cancel>取消</span>
      <span class="am-modal-btn" data-am-modal-confirm>确定</span>
    </div>
  </div>
</div>
<script>
var pager = null;
$(function(){
	pager = $("#am-page").pagination({totalPage:${pager.pageCount}, pageNum: 6, refresh: queryPage});
	$("#btn_view").bind({click: view});
	$("#btn_batch").bind({click: batchAudit});
	$("#select_all").bind({click:function(){
			if(this.checked){
				$("#pageList input[type='checkbox']").prop("checked",true);
			}else{
				$("#pageList input[type='checkbox']").prop("checked",false);
			}
		}	
	});
});
function loadPager(totalPage){
	if(${pager.pageCount} != totalPage){
		pager = $("#am-page").pagination({totalPage:totalPage, pageNum: 6, refresh: queryPage});
	}
}
function batchAudit(){
	var ids = [];
	$("#pageList input[type='checkbox']:checked").each(function(){
		ids.push($(this).next().val());
	});
	if(ids.length == 0){
		$.dialog({
			id:'alert1', 
			title: '请至少选择一条记录', 
			type:2
		});
		return;
	}
	$.dialog({
		id:'confirm1', 
		title: '确定要审批吗？', 
		type:3,
		confirm:function(){doBatchAudit();},
		cancel:function(){}
	});
}
function doBatchAudit(){
	var ids = [];
	$("#pageList input[type='checkbox']:checked").each(function(){
		ids.push($(this).next().val());
	});
	doAudit(ids);
}
function doAudit(ids){
	var bean = new Object();
	bean.ids = ids;
	doAjax("${ctx}/admin/goods/ex/doAuditPass.do",bean, function(data){
		if(data.success == 1){
			queryPage(pager.getCurrentPage());
		}
	});
}
function queryPage(pageNo){
	var bean = new Object();
	bean.pageSize = ${pager.pageSize};
	bean.pageNo = pageNo;
	var url = window.location+'';
	var params = url.indexOf("?")>0?url.substring(url.indexOf("?")):"";
	doAjax("${ctx}/admin/goods/ex/pager.do"+params,bean, function(data){
		$("#pageList").empty();
		$("#pageList").append(data);
	},'html');
}
function openDialog(){
	$.dialog({
		id:'edit', title: '编辑', 
		width:400, height:300, 
		url:'${ctx}/page/load.do?url=admin/edit'
	});
}
function search(bean){
	var url = '${ctx}/admin/goods/ex/audit.do?state=0';
	for(p in bean){
		if(url.indexOf("?") == -1){
        	url += "?"+p+"="+bean[p];
        }else{
        	url += "&"+p+"="+bean[p];
        }
	}
	window.location.href = url;
}
function view(){
	var ids = [];
	$("#pageList input[type='checkbox']:checked").each(function(){
		ids.push($(this).next().val());
	});
	if(ids.length != 1){
		$.dialog({
			id:'alert_view', 
			title: '请选择一条记录', 
			type:2
		});
		return;
	}
	$.dialog({
		id:'view_unpass', title: '', 
		type:1,
		width:400, height:500, 
		url:'${ctx}/admin/goods/ex/view.do?id='+ids[0]
	});
}
</script>

</form>

</div>

</div>
</body>
</html>
